/*
 * Copyright (c) 2006, 2022, webrx.cn All rights reserved.
 *
 */
package chat02;

import java.io.BufferedReader;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * <p>Project: jse2204 - ChatUtil
 * <p>Powered by webrx On 2022-09-29 15:32:34
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public class ChatUtil {
    private PrintWriter writer;
    private BufferedReader reader;
    private String title;

    public ChatUtil(PrintWriter writer, BufferedReader reader, String title) {
        this.writer = writer;
        this.reader = reader;
        this.title = title;
    }

    /**
     * 发信息
     */
    public void a() {
        while (true) {
            //发信息
            String info = title + ":" + new Scanner(System.in).nextLine() + "\r\n";
            writer.write(info);
            writer.flush();
        }
    }

    public void b() {
        while (true) {
            try {
                //先收信息
                String msg = reader.readLine();//
                System.out.println(msg);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }


    public PrintWriter getWriter() {
        return writer;
    }

    public void setWriter(PrintWriter writer) {
        this.writer = writer;
    }

    public BufferedReader getReader() {
        return reader;
    }

    public void setReader(BufferedReader reader) {
        this.reader = reader;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

}
